#include "HousekeepingGrid.h"
#include <assert.h>


/*TODO: Ich habe hier erstmal generell angenommen, dass die erste Spalte in wxWidgets die
 * 		nullte ist. Einfach im Hinterkopf behalten.
 */



int HousekeepingDataBase::GetNumberRows() {
	return data.size();
}

int HousekeepingDataBase::GetNumberCols() {
	return numCols;
}

bool HousekeepingDataBase::IsEmptyCell(int row, int col) {
	return false;
}

wxString HousekeepingDataBase::GetValue(int row, int col) {
	StatusData& temp = data[row];

	wxString retString;
	switch(col) {
	case 0:
		return retString<<temp.posX;
	case 1:
		return retString<<temp.posY;
	case 2:
		return retString<<temp.posZ;
	case 3:
		return retString<<temp.temperature;
	default:
		return retString;
	}
}

wxString HousekeepingDataBase::GetType(int row, int col) {
	return wxGRID_VALUE_DOUBLE;
}

bool HousekeepingDataBase::CanGetValueAs(int row, int col, wxString& typeName) {
	if(typeName.IsSameAs(wxGRID_VALUE_DOUBLE) || typeName.IsSameAs(wxGRID_VALUE_STRING)) return true;
	return false;
}

bool HousekeepingDataBase::CanSetValueAs(int row, int col, wxString& typeName) {
	return false;
}

double HousekeepingDataBase::GetValueAsDouble(int row, int col) {
	StatusData& temp = data[row];

	switch(col) {
	case 0:
		return temp.posX;
	case 1:
		return temp.posY;
	case 2:
		return temp.posZ;
	case 3:
		return temp.temperature;
	default:
		return 0;
	}
}

void HousekeepingDataBase::SetView(wxGrid *view) {
	tableView = view;
}

wxGrid* HousekeepingDataBase::GetView() {
	return tableView;
}

void HousekeepingDataBase::Clear() {
	data.clear();
}

wxString HousekeepingDataBase::GetColLabelValue(int col) {
	switch(col) {
	case 0: return "PosX";
	case 1: return "PosY";
	case 2: return "PosZ";
	case 3: return "Temperature";
	default: return "";
	}
}

bool HousekeepingDataBase::putGeneric(const unsigned int len, const void *msg)
{
	assert(sizeof(NodeMetaData) != sizeof(StatusData));
	//Detect message type by length of message
	//This is possible due to the fixed lengths of the topic messages
	if(len == sizeof(StatusData)) {
		data.push_back(*(StatusData*)msg);
	}else{
		//Parse the shit outa that message!!
	}
	return true;
}




